<?php
class Orm_Oci
{	
	private $db = null;
	public function __construct(){
		if($this->db == NULL){
            header("Content-type: text/html; charset=utf-8"); 
            $this->db = oci_connect('bqe','bqe','123.57.47.91:1521/bqedb','AL32UTF8');
		}

		if(!$this->db){
        	$e = oci_error();
            Tool_Fnc::ajaxMsg(htmlentities($e['message'], ENT_QUOTES));
        }else{
            return $this->db; 
        }
				
	}

    public function getRow($tSql){
        $stid = oci_parse($this->db, $tSql);
        $r = oci_execute($stid);
        $row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS);
        return $row;
    }

    public function getAll($tSql){
        $stid = oci_parse($this->db, $tSql);
        $r = oci_execute($stid);
        $tDatas = array();
        while($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)){
            $tDatas[] = $row; 
        }
        return $tDatas;
    }
   
    public function exec($tSql){
        $stid = oci_parse($this->db, $tSql);
        return  oci_execute($stid);
    }

	public function __destruct(){
		if(!empty($this->db)){
            oci_close($this->db);
		}			
	}
}

